<!-- 表单弹窗 -->
<form id="question-form" lay-filter="question-form" class="layui-form model-form">
    <input name="quesid" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="layui-badge-dot"></span>问题标题</label>
        <div class="layui-input-block">
            <input name="qtitle" placeholder="请输入问题标题" type="text" class="layui-input"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="layui-badge-dot"></span>问题题型</label>
        <div class="layui-input-block">
            <input type="radio" name="qutype" value="1" title="单选" checked/>
            <input type="radio" name="qutype" value="2" title="多选"/>
            <input type="radio" name="qutype" value="3" title="主观"/>
        </div>
    </div>
    <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
        <button class="layui-btn" lay-filter="question-form-submit" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'admin', 'form'], function () {
        let layer = layui.layer;
        let admin = layui.admin;
        let form = layui.form;

        let data = admin.getTempData('t_question');
        form.val('question-form', data);
        if (data) {
            let qtitle = $("input[name='qtitle']");
            qtitle.attr('disabled', true);
            qtitle.attr('class', "layui-input layui-disabled");
            $("input[name='qutype'][value='" + data.qutype + "']").next().click();
        }
        form.render();

        // 表单提交事件
        form.on('submit(question-form-submit)', function (data) {
            layer.load(2);
            admin.req('api-paper/question/saveOrUpdate', JSON.stringify(data.field), function (data) {
                layer.closeAll('loading');
                if (data.code === 0) {
                    layer.msg(data.msg, {icon: 1, time: 500});
                    admin.finishPopupCenter();
                } else {
                    layer.msg(data.msg, {icon: 2, time: 500});
                }
            }, 'post');
            return false;
        });
    });
</script>
